package com.vitogiovanni.tobook;

import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.Toast;

public class FullImageActivity extends Activity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_full_image);
		//getActionBar().hide();
		
		Intent i = getIntent();
		 
		Bitmap foto = (Bitmap) i.getParcelableExtra("bitmap");
        //ImageAdapter imageAdapter = new ImageAdapter(this);
		if(foto!=null){
			FrameLayout frameLayout = (FrameLayout) findViewById(R.id.image_dialog_root);
			
			Display display = getWindowManager().getDefaultDisplay();
			Point size = new Point();
			display.getSize(size);
			int width = size.x;
			int height = size.y;
			double w,h;
			
			double rapporto = ((double)foto.getWidth())/((double)foto.getHeight());
			if(rapporto>=1){
				w = 0.8* (double)width;
				h = w/rapporto;
				if(h>0.8*height)
				{
					h = 0.8*(double)height;
					w = h*rapporto;
				}
			}
			else{
				h = 0.8*(double)height;
				w = h*rapporto;
				if(w>0.8*width)
				{
					w = 0.8*(double)width;
					h = w/rapporto;
				}
			}
			FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams((int)w, (int)h);
			ImageView imageView = (ImageView) findViewById(R.id.full_image_view);
			frameLayout.setLayoutParams(layoutParams);
			imageView.setImageBitmap(foto);
		}
		else{
			Toast.makeText(getApplicationContext(), getResources().getString(R.string.error_caricamento_foto), Toast.LENGTH_SHORT).show();
		}
	}
	/*
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {

		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.full_image, menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		// Handle action bar item clicks here. The action bar will
		// automatically handle clicks on the Home/Up button, so long
		// as you specify a parent activity in AndroidManifest.xml.
		int id = item.getItemId();
		if (id == R.id.action_settings) {
			return true;
		}
		return super.onOptionsItemSelected(item);
	}
	*/

}
